<template>
    <div>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-card shadow="hover" class="mgb20" style="height:252px;">
            <div class="user-info">
              <!--src="../assets/img/img.jpg"-->
              <img :src="user.avatar" class="user-avator" alt />
              <div class="user-info-cont">
                <div class="user-info-name">{{ user.username }}</div>
                <div>{{ user.type=0?'系统管理员':'系统用户' }}</div>
              </div>
            </div>
            <div class="user-info-list">
              上次登录时间：
              <span>2021-11-12</span>
            </div>
            <div class="user-info-list">
              上次登录地点：
              <span>梧州</span>
            </div>
          </el-card>
          <el-card shadow="hover" style="height:252px;">
            <template #header>
              <div class="clearfix">
                <span>{{infoMessage?infoMessage:'个人信息'}}</span>
                <el-button style="float: right; padding: 3px 0" type="text" @click="dialogVisible=true">{{addOrUpdate?'去完善':'去修改'}}</el-button>
              </div>
            </template>
            <div v-if="comfirm">
              <el-descriptions :column="1">
                <el-descriptions-item label="姓名">{{myMessage.hostName}}</el-descriptions-item>
                <el-descriptions-item label="手机号">{{myMessage.phone}}</el-descriptions-item>
                <el-descriptions-item label="邮箱">{{myMessage.email}}</el-descriptions-item>
                <el-descriptions-item label="身份证">{{myMessage.idNumber}}</el-descriptions-item>
                <el-descriptions-item label="联系地址">{{myMessage.address}}</el-descriptions-item>
              </el-descriptions>
            </div>
            <div v-if="noComfirm" style="margin-left: 20px ;margin-top: 20px">
              <el-skeleton :rows="4" animated />
                <!--<el-button type="primary" plain @click="dialogVisible=true">去完善</el-button>-->
            </div>
          </el-card>
        </el-col>
        <el-col :span="16">
          <el-row :gutter="20" class="mgb20">
            <el-col :span="8">
              <el-card shadow="hover" :body-style="{ padding: '0px' }">
                <div class="grid-content grid-con-1">
                  <i class="el-icon-user-solid grid-con-icon"></i>
                  <div class="grid-cont-right">
                    <div class="grid-num">{{firstMsg}}</div>
                    <div>待收货</div>
                  </div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="8">
              <el-card shadow="hover" :body-style="{ padding: '0px' }">
                <div class="grid-content grid-con-2">
                  <i class="el-icon-message-solid grid-con-icon"></i>
                  <div class="grid-cont-right">
                    <div class="grid-num">{{secondMsg}}</div>
                    <div>待处理</div>
                  </div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="8">
              <el-card shadow="hover" :body-style="{ padding: '0px' }">
                <div class="grid-content grid-con-3">
                  <i class="el-icon-s-goods grid-con-icon"></i>
                  <div class="grid-cont-right">
                    <div class="grid-num">{{thirdMsg}}</div>
                    <div>成交额</div>
                  </div>
                </div>
              </el-card>
            </el-col>
          </el-row>
          <el-card shadow="hover" style="height:403px;">
            <template #header>
              <div class="clearfix">
                <span>待办事项</span>
                <el-button style="float: right; padding: 3px 0" type="text">添加</el-button>
              </div>
            </template>

            <el-table :show-header="false" :data="todoList" style="width:100%;">
              <el-table-column width="40">
                <template #default="scope">
                  <el-checkbox v-model="scope.row.status"></el-checkbox>
                </template>
              </el-table-column>
              <el-table-column>
                <template #default="scope">
                  <div class="todo-item" :class="{
                                        'todo-item-del': scope.row.status,
                                    }">{{ scope.row.title }}</div>
                </template>
              </el-table-column>
              <el-table-column width="60">
                <template>
                  <i class="el-icon-edit"></i>
                  <i class="el-icon-delete"></i>
                </template>
              </el-table-column>
            </el-table>
          </el-card>
        </el-col>
      </el-row>
      <!--弹框-->
      <el-dialog :title="addOrUpdate?'完善个人信息':'修改个人信息'" :visible.sync="dialogVisible" width="600px">
        <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
          <el-form-item label="姓名：" prop="storeHost">
            <el-input v-model="formData.storeHost" placeholder="请输入单行文本姓名" clearable suffix-icon='el-icon-user'
                      :style="{width: '100%'}"></el-input>
          </el-form-item>
          <el-form-item label="身份证号：" prop="idNumber">
            <el-input v-model="formData.idNumber" placeholder="请输入身份证号" :maxlength="18" show-word-limit clearable
                      :style="{width: '100%'}"></el-input>
          </el-form-item>
          <el-form-item label="手机号：" prop="phone">
            <el-input v-model="formData.phone" placeholder="请输入手机号" :maxlength="11" show-word-limit clearable
                      :style="{width: '100%'}"></el-input>
          </el-form-item>
          <el-form-item label="邮箱：" prop="email">
            <el-input v-model="formData.email" placeholder="请输入邮箱" clearable suffix-icon='el-icon-folder-opened'
                      :style="{width: '100%'}"></el-input>
          </el-form-item>
          <el-form-item label="地址：" prop="address">
            <el-input v-model="formData.address" type="textarea" placeholder="请输入地址"
                      :autosize="{minRows: 3, maxRows: 3}" :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer">
          <el-button @click="close">取消</el-button>
          <el-button type="primary" @click="handelConfirm">确定</el-button>
        </div>
      </el-dialog>
    </div>
</template>

<script>
  export default {
    name: 'PerData',
    data(){
      return{
        //将存在sessionStorage的字符串获取出来转换成对象
        user:JSON.parse(window.sessionStorage.getItem('user')),
        myMessage:{},
        infoMessage:'',
        noComfirm:false,
        comfirm:false,
        addOrUpdate:false,
        dialogVisible: false,
        formData: {
          userId:undefined,
          perStore:0,
          storeHost: undefined,
          idNumber: undefined,
          phone: undefined,
          email: undefined,
          address: undefined,
        },
        rules: {
          storeHost: [{
            required: true,
            message: '请输入单行文本姓名',
            trigger: 'blur'
          }],
          idNumber: [{
            required: true,
            message: '请输入身份证号',
            trigger: 'blur'
          }],
          phone: [{
            required: true,
            message: '请输入手机号',
            trigger: 'blur'
          }],
          email: [{
            required: true,
            message: '请输入邮箱',
            trigger: 'blur'
          }],
          address: [{
            required: true,
            message: '请输入地址',
            trigger: 'blur'
          }],
        },
        firstMsg:'',
        secondMsg:'',
        thirdMsg:'',
        todoList:[
          {
            title: "今天要修复100个bug",
            status: false,
          },
          {
            title: "今天要修复100个bug",
            status: false,
          },
          {
            title: "今天要写100行代码加几个bug吧",
            status: false,
          },
          {
            title: "今天要修复100个bug",
            status: false,
          },
          {
            title: "今天要修复100个bug",
            status: true,
          },
          {
            title: "今天要写100行代码加几个bug吧",
            status: true,
          },
        ],
      }
    },
    mounted () {
      this.initComfirm();
      this.initOther();
    },
    methods:{
      initOther(){
        this.getRequest('/rent/data/RentCount/?userId='+this.user.userId).then(resp => {
          if (resp) {
            this.firstMsg=resp.message
          }
        })
        this.getRequest('/rent/data/HandleCount/?myUseId='+this.user.userId).then(resp => {
          if (resp) {
            this.secondMsg=resp.message
          }
        })
        this.getRequest('/rent/data/PriceCount/?myUseId='+this.user.userId).then(resp => {
          if (resp) {
            this.thirdMsg=resp.message
          }
        })
      },
      // 完善个人信息
      handelConfirm() {
        this.$refs['elForm'].validate(valid => {
          if (!valid) return
          this.formData.userId=this.user.userId
          console.log(this.formData)
          this.postRequest('/personal/data/comfirm/add',this.formData).then(resp => {
            if (resp) {
              this.$notify.success({ title: '信息', message: '已提交审核，请等待'});
              this.dialogVisible=false
            }
          })
        })
      },
      close(){
        this.dialogVisible=false
        this.$notify.info({ title: '信息', message: '已取消操作'});
      },
      //查询认证信息
      initComfirm () {
        this.infoMessage=''
        this.formData=''
        this.postRequest('/personal/data/comfirmByuserId/'+this.user.userId).then(resp => {
          if (resp.code===200) {
            this.addOrUpdate=false
            if (resp.message==='ok'){
              this.formData=resp.obj
              this.comfirm=true
              this.myMessage=resp.obj
            } else{
              //提示等待
              this.formData=resp.obj
              this.noComfirm=true
              this.infoMessage=resp.message
            }
          }else if(resp.code===500){
            // 按钮事件，提示去完善
            this.addOrUpdate=true
            this.noComfirm=true
            this.infoMessage=resp.message
          }
        })
      },
    }
  }
</script>

<style scoped>
  .el-row {
    margin-bottom: 20px;
  }

  .grid-content {
    display: flex;
    align-items: center;
    height: 100px;
  }

  .grid-cont-right {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: #999;
  }

  .grid-num {
    font-size: 30px;
    font-weight: bold;
  }

  .grid-con-icon {
    font-size: 50px;
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    color: #fff;
  }

  .grid-con-1 .grid-con-icon {
    background: rgb(45, 140, 240);
  }

  .grid-con-1 .grid-num {
    color: rgb(45, 140, 240);
  }

  .grid-con-2 .grid-con-icon {
    background: rgb(100, 213, 114);
  }

  .grid-con-2 .grid-num {
    color: rgb(45, 140, 240);
  }

  .grid-con-3 .grid-con-icon {
    background: rgb(242, 94, 67);
  }

  .grid-con-3 .grid-num {
    color: rgb(242, 94, 67);
  }

  .user-info {
    display: flex;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #ccc;
    margin-bottom: 20px;
  }

  .user-avator {
    width: 120px;
    height: 120px;
    border-radius: 50%;
  }

  .user-info-cont {
    padding-left: 50px;
    flex: 1;
    font-size: 14px;
    color: #999;
  }

  .user-info-cont div:first-child {
    font-size: 30px;
    color: #222;
  }

  .user-info-list {
    font-size: 14px;
    color: #999;
    line-height: 25px;
  }

  .user-info-list span {
    margin-left: 70px;
  }

  .mgb20 {
    margin-bottom: 20px;
  }

  .todo-item {
    font-size: 14px;
  }

  .todo-item-del {
    text-decoration: line-through;
    color: #999;
  }

  .schart {
    width: 100%;
    height: 300px;
  }
</style>
